function msg = setlogging(signal,currsys,mode)

% SETLOGGING   set logging signals 
% 
% SYNTAX
% function msg = setlogging(signal,sys,mode)
% function msg = setlogging(signal,sys)
% function msg = setlogging(signal,mode)
% Function return error message
%
% Input parameters:
%   signal    the signal name that need logging
%   sys				the system that the signal you want to search
%				default the root system
%   remove		setlogging mode
%       {'on','off'} defalut set logging on
% 
% Output parameters:
% msg          error message

% $Revision: 1.00 $ $Date: 2013/04/21 15:00:27 $
% Copyright (c) Changan New Energy Vechile,Chongqing LTD.,
% author:   Xiaobiao Huang, BCU

msg = [];
if nargin < 3
	mode = 'on';
end

if nargin < 2
	currsys = gcs;
end
if isstruct(signal)
	f = fieldnames(signal);
end
if iscell(signal)
	f = signal(:,1);
end

ln = length(f);
for i=1:ln
    Signal = f{i,1};
    Tag = find_system(currsys,'findall','on','lookundermasks','all','Type','port','name',Signal);
    if isempty(Tag)
        Tag = find_system(currsys,'findall','on','lookundermasks','all','Type','port','name',['<' Signal '>']);        
    end
    if isempty(Tag)
        disp(['the signal you want to log ' Signal  ' is not exist.']);
    end
    Cmp_Tag = find_system(currsys,'findall','on','LookUnderMasks','all','Type','port','name',['cmp_' Signal]);
    if isempty(Cmp_Tag)
        Cmp_Tag = find_system(currsys,'findall','on','lookundermasks','all','Type','port','name',['<cmp_' Signal '>']);
    end
%     if isempty(Cmp_Tag)
%         disp(['cmp_' SignalSignal 'is not found.Check your modle and try again!');
%     end
    if ~isempty(Tag)
      if length(Tag) > 1
        %sprintf(['The signal :' f{i,1} 'you want to logging is dumplicated.'])
        %msg = ['dumplicated signal:' f{i,1}];
        %return;
        set_param(Tag(1),'DataLogging',mode);
      else
      set_param(Cmp_Tag,'DataLogging',mode);
      set_param(Tag,'DataLogging',mode);
      end
    end
end

